#ifndef DATABASEENGINE_H
#define DATABASEENGINE_H

#include <QObject>
#include <QQmlListProperty>
#include "databaseinterface.h"
#include "person.h"
#include "login.h"
#include "curriculum.h"

class DatabaseEngine : public QObject
{
    Q_OBJECT
public:
    static DatabaseEngine* Instance();
    //用户登录密码判断
    Q_PROPERTY(bool passwordpair READ getPassword NOTIFY passwordPairChanged)
    //个人页
    Q_PROPERTY(Person* persondata READ getPersondata NOTIFY persondataChanged)
    //本地登录账号
    Q_PROPERTY(Login* local READ getLocal)
    //精品课程
    Q_PROPERTY(QQmlListProperty<Curriculum> curriculum READ getCurriculum NOTIFY curriculumChanged)
    //是否已参加此课程
    Q_PROPERTY(bool isselectcur READ getIsSelectCur NOTIFY isSelectCurChanged)
    //已选课程
    Q_PROPERTY(QQmlListProperty<Curriculum> mycurriculum READ getMyCurriculum NOTIFY mycurriculumChanged)

    Q_INVOKABLE void log(QString userid,QString pwd);
    Q_SIGNAL void passwordPairChanged();
    Q_INVOKABLE bool getPassword();

    Q_INVOKABLE Person* getPersondata();
    Q_SIGNAL void persondataChanged();

    Q_INVOKABLE void rememberlocal(QString id,QString pwd);
    Q_INVOKABLE Login* getLocal();

    //更改信息
    Q_INVOKABLE void setPersondata(QString id,QString phone,QString email);

    Q_INVOKABLE void setChangedPassword(QString pwd);

    //课程查询
    Q_INVOKABLE QQmlListProperty<Curriculum> getCurriculum();
    Q_SIGNAL void curriculumChanged();

    //参加课程
    Q_INVOKABLE void joinCurriculum(int cur_id);

    //此课程是否已选
    Q_INVOKABLE void isSelectCur(int cur_id);
    Q_INVOKABLE bool getIsSelectCur();
    Q_SIGNAL void isSelectCurChanged();

    //已选课程
    Q_INVOKABLE void setMyCurriculum();
    Q_INVOKABLE QQmlListProperty<Curriculum> getMyCurriculum();
    Q_SIGNAL void mycurriculumChanged();
private:
    explicit DatabaseEngine();

private:
    bool                    passwordpair{false};
    Person                  *m_persondata;
    Login                   *m_local;
    QVector<Curriculum>     m_curriculum;
    DatabaseInterface       *m_databaseinterface{nullptr};
};

#endif // DATABASEENGINE_H
